using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace SharpNote.Core.Data
{
    /// <summary>
    /// 说明对象属性与数据表中字段的映射信息。
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class FieldMappingAttribute : Attribute
    {
        #region Fields & Properties

        private bool _isPrimaryKey = false;

        /// <summary>
        /// 获取或设置是否为主键。
        /// </summary>
        public bool IsPrimaryKey
        {
            get { return _isPrimaryKey; }
            set { _isPrimaryKey = value; }
        }

        private DbType _dbType;

        public DbType DbType
        {
            get { return _dbType; }
            set { _dbType = value; }
        }

        private bool _ignoreWhenInsert = false;

        /// <summary>
        /// 获取或设置在执行 Insert 语句时，是否忽略此字段。
        /// </summary>
        public bool IgnoreWhenInsert
        {
            get { return _ignoreWhenInsert; }
            set { _ignoreWhenInsert = value; }
        }

        private bool _ignoreWhenUpdate = false;

        /// <summary>
        /// 获取或设置在执行 Update 语句时，是否忽略此字段。
        /// </summary>
        public bool IgnoreWhenUpdate
        {
            get { return _ignoreWhenUpdate; }
            set { _ignoreWhenUpdate = value; }
        }


        #endregion

        #region Constructors

        /// <summary>
        /// 实例化 FieldMappingAttribute。
        /// </summary>
        /// <param name="isPrimaryKey">是否为主键</param>
        public FieldMappingAttribute(bool isPrimaryKey, DbType dbType)
        {
            _isPrimaryKey = isPrimaryKey;
            _dbType = dbType;
        }

        public FieldMappingAttribute(bool isPrimaryKey, DbType dbType, bool ignoreWhenInsert, bool ignoreWhenUpdate)
        {
            _isPrimaryKey = isPrimaryKey;
            _dbType = dbType;
            _ignoreWhenInsert = ignoreWhenInsert;
            _ignoreWhenUpdate = ignoreWhenUpdate;
        }

        #endregion
    }
}
